\section{Source/Vector.c}


\begin{footnotesize}\begin{alltt}
00001 \textcolor{preprocessor}{#include <stdlib.h>}
00002 \textcolor{preprocessor}{#include <math.h>}
00003 \textcolor{preprocessor}{#include "Vector.h"}
00004 
00005 \textcolor{keyword}{inline} Vector *Vector\_Create()
00006 \{
00007     Vector *Vector=malloc(\textcolor{keyword}{sizeof}(Vector));
00008     \textcolor{keywordflow}{if} (Vector!=NULL)
00009     \{
00010         Vector->X=0.0;
00011         Vector->Y=0.0;
00012         Vector->Z=0.0;
00013     \}
00014     \textcolor{keywordflow}{return} Vector;
00015 \}
00016 
00017 \textcolor{keyword}{inline} \textcolor{keywordtype}{void} Vector\_Destroy(Vector *Vector)
00018 \{
00019     free(Vector);
00020 \}
00021 
00022 \textcolor{keyword}{inline} \textcolor{keywordtype}{float} Vector\_Length(Vector *Vector)
00023 \{
00024     \textcolor{keywordflow}{return} sqrt(Vector->X*Vector->X+Vector->Y*Vector->Y+Vector->Z*Vector->Z);
00025 \}
00026 
00027 
00028 \textcolor{keyword}{inline} \textcolor{keywordtype}{void} Vector\_Scale(Vector *Vector, \textcolor{keywordtype}{float} Scale)
00029 \{
00030     Vector->X*=Scale;
00031     Vector->Y*=Scale;
00032     Vector->Z*=Scale;
00033 \}
00034 
00035 \textcolor{keyword}{inline} \textcolor{keywordtype}{void} Vector\_Normalize(Vector *Vector)
00036 \{
00037     \textcolor{keywordtype}{float} ReciprocalLength=1/Vector\_Length(Vector);
00038     Vector->X*=ReciprocalLength;
00039     Vector->Y*=ReciprocalLength;
00040     Vector->Z*=ReciprocalLength;
00041 \}
00042 
00043 \textcolor{keyword}{inline} \textcolor{keywordtype}{float} Vector\_DotProduct(Vector *Vector0, Vector *Vector1)
00044 \{
00045     \textcolor{keywordflow}{return} Vector0->X*Vector1->X+Vector0->Y*Vector1->Y+Vector0->Z*Vector1->Z;
00046 \}
00047 
00048 \textcolor{keyword}{inline} \textcolor{keywordtype}{void} Vector\_CrossProduct(Vector *Result, Vector *Vector0, Vector *Vector1)
      
00049 \{
00050     Result->X=Vector0->Y*Vector1->Z-Vector0->Z*Vector1->Y;
00051     Result->Y=Vector0->Z*Vector1->X-Vector0->X*Vector1->Z;
00052     Result->Z=Vector0->X*Vector1->Y-Vector0->Y*Vector1->X;
00053 \}
00054 
00055 \textcolor{keyword}{inline} \textcolor{keywordtype}{void} Vector\_Add(Vector *Result, Vector *Vector0, Vector *Vector1)
00056 \{
00057     Result->X=Vector0->X+Vector1->X;
00058     Result->Y=Vector0->Y+Vector1->Y;
00059     Result->Z=Vector0->Z+Vector1->Z;
00060 \}
00061 
00062 \textcolor{keyword}{inline} \textcolor{keywordtype}{void} Vector\_Subtract(Vector *Result, Vector *Vector0, Vector *Vector1)
00063 \{
00064     Result->X=Vector0->X-Vector1->X;
00065     Result->Y=Vector0->Y-Vector1->Y;
00066     Result->Z=Vector0->Z-Vector1->Z;
00067 \}
\end{alltt}\end{footnotesize}
